package com.tech4u.edu4u_demo;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

import androidx.annotation.Nullable;

public class VolumnView extends View {

    int mWidth, mHeight;

    Rect rect = new Rect(0, 0, 0, 0);
    Paint paint;

    public VolumnView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        paint = new Paint();
        paint.setStyle(Paint.Style.FILL_AND_STROKE);
        paint.setStrokeWidth(10);
        paint.setColor(context.getResources().getColor(R.color.green));

    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        mWidth = getWidth();
        mHeight = getHeight();
        canvas.drawRect(rect, paint);
    }

    public void updateProgress(int progress) {
        rect = new Rect(0, (100 - progress) * mHeight / 100, mWidth, mHeight);
        invalidate();
    }
}
